package com.wei.order.service;

import com.wei.common.entity.Charge;
import com.wei.common.entity.Order;
import com.wei.common.service.ChargeService;
import com.wei.common.service.OrderService;
import com.wei.common.service.StorageService;
import com.wei.order.dao.OrderMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author weichuanyuan
 * @version 1.0
 * @date 2021/8/29 9:37
 */
@Service
@GlobalTransactional
public class OrderServiceImpl implements OrderService {

    @DubboReference
    private ChargeService chargeService;

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public boolean checkOrder(Order order) {
        System.out.println("校验订单");
        return true;
    }

    @Override
    public boolean placeOrder(Order order) {
        System.out.println("下订单");
        orderMapper.insert(order);

        Charge charge = new Charge();
        charge.setChargeTime(new Date());
        charge.setChargeAmount(order.getOrderAmount());
        charge.setChargeType("01");
        chargeService.Charging(charge);
        return true;
    }
}
